#!/bin/bash

mvn package

runningid=`docker ps | grep -i dockertest_demo  | awk '{print $1}'`
imagesid=`docker images|grep -i dockertest_demo | awk '{print $3}'`

#project=$JENKINS_HOME/workspace/demo
project=/tools/git/demo/

if [ -n "$runningid" ];then
	echo "stop $runningid"
	docker stop $runningid  
else
    echo "not run"
fi


if  [ -n "$imagesid" ];then
	echo "rmi  $imagesid "
	docker rmi -f  $imagesid  
else
    echo "image is null"
fi


cd $project

docker build -t dockertest_demo $project

if docker ps -a|grep -i dockertest_demo;then
   docker rm -f dockertest_demo
fi

docker run -it -d -p 8899:8080   dockertest_demo